package com.aaa.json.service;





import com.aaa.json.dao.EmpDao;
import com.aaa.json.dao.EmpDaoImpl;
import com.aaa.json.entity.Emp;

import java.util.List;
import java.util.Map;

/**
 * @program: javamvc-mvcup
 * @description:
 * @author: 诸葛龙辰
 * @create: 2023-03-03 19:03
 * @version:
 **/
public class EmpServiceImpl implements EmpService{
    @Override
    public List<Map> queryByPage(int pageNo, int pageSize, Emp emp) {
        //计算开始值
        int start = (pageNo-1)*pageSize;
        //执行查询
        return empDao.queryByPage(start,pageSize,emp);
    }

    @Override
    public int queryTotal(Emp emp) {
        return empDao.queryTotal(emp);
    }

    //引入dao
    private EmpDao empDao = new EmpDaoImpl();
    @Override
    public List<Map> queryAll() {
        return empDao.queryAll();
    }

    @Override
    public Emp queryById(int empId) {
        //根据编号查询集合
        List<Map> mapList = empDao.queryById(empId);
        //定义emp对象
        Emp emp = null;
        if(mapList!=null&&mapList.size()>0){
            Map map = mapList.get(0);
            //Integer empId, String empName, String sex, String phoneNum, String province, String hireDate, Integer deptNo, double salary, String password
            emp = new Emp(Integer.valueOf(map.get("emp_id").toString()),map.get("emp_name")+"",map.get("sex")+"",
                    map.get("phone_num")+"",map.get("province")+"",
                    map.get("hire_date")+"",Integer.valueOf(map.get("dept_no")+""),
                    Double.valueOf(map.get("salary")+""),map.get("password")+"");
        }
        return emp;
    }

    @Override
    public int add(Emp emp) {
        return empDao.add(emp);
    }

    @Override
    public int update(Emp emp) {
        return empDao.update(emp);
    }

    @Override
    public int deleteById(int empId) {
        return empDao.deleteById(empId);
    }

    @Override
    public Map queryByParam(Emp emp) {
        //查询列表
        List<Map> mapList = empDao.queryByParam(emp);
        //判断是否存在
        if(mapList!=null&&mapList.size()>0){
            //存在返回true
            return mapList.get(0);
        }
        return null;
    }
}
